
local file = io.open(arg[1]);
assert(file);

local out = false;
for line in file:lines()do
    if(line:match('sst_vpaned_height'))then
        out = true;
    elseif(out and line:match('^%['))then
        out = false;
    elseif(out)then
        if(not line:match('@'))then
            if(not line:match('%['))then
                --单信号
                local s = '<Signal capture_enable="true">#SIG#</Signal>';
                local n = line:match('%.([%w_%.]+)');
                n = n:gsub('%.','/');
                s = s:gsub('#SIG#',n);
                print(s);
            else
                local s = '<Bus capture_enable="true" name="#SIG#">'
                local n = line:match('%.([^\n]+)');
                local h,l = line:match('(%d+):(%d+)');
                h,l = tonumber(h),tonumber(l);
                n = n:gsub('%.','/');
                s = s:gsub('#SIG#',n);
                print(s);
                for a=h,l,-1 do
                    n = line:match('%.([%w_%.]+)');
                    n = n:gsub('%.','/');
                    s = '<Signal>#SIG#</Signal>';
                    s = s:gsub('#SIG#',string.format('%s[%d]',n,a));
                    print(s);
                end
                print('</Bus>');
            end
        end
    end
end

